// SH_BPA.cpp: implementation of the CSH_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/SH_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSH_BPA::CSH_BPA()
{
	m_chType = 'S';
	m_chSubType = 'H';
	m_chChangeCode = ' ';

	m_dTd = 0;
	m_dT1 = 0;
	m_dT2 = 0;
	m_dT3 = 0;
	m_dK0 = 0;
	m_dK1 = 0;
	m_dK2 = 0;
	m_dK3 = 0;
	m_dK = 0;
	m_dVsmax = 0;
	m_dVsmin = 0;
	m_dKp = 0;
	m_dKmva = 0;

	m_strCardType[0] = 'S';
}

CSH_BPA::CSH_BPA(CSH_BPA &shBPA):CUnit_BPA(shBPA)
{
	m_dTd = shBPA.m_dTd;
	m_dT1 = shBPA.m_dT1;
	m_dT2 = shBPA.m_dT2;
	m_dT3 = shBPA.m_dT3;
	m_dK0 = shBPA.m_dK0;
	m_dK1 = shBPA.m_dK1;
	m_dK2 = shBPA.m_dK2;
	m_dK3 = shBPA.m_dK3;
	m_dK = shBPA.m_dK;
	m_dVsmax = shBPA.m_dVsmax;
	m_dVsmin = shBPA.m_dVsmin;
	m_dKp = shBPA.m_dKp;
	m_dKmva = shBPA.m_dKmva;
}

CSH_BPA::~CSH_BPA()
{

}

bool CSH_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSH_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dTd = StrToDouble(&buffer[16],5,4);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dT1 = StrToDouble(&buffer[21],5,3);
	if(EndOfSec(&buffer[21],5))
		return true;

	m_dT2 = StrToDouble(&buffer[26],5,3);
	if(EndOfSec(&buffer[26],5))
		return true;

	m_dT3 = StrToDouble(&buffer[31],5,3);
	if(EndOfSec(&buffer[31],5))
		return true;

	m_dK0 = StrToDouble(&buffer[36],5,4);
	if(EndOfSec(&buffer[36],5))
		return true;

	m_dK1 = StrToDouble(&buffer[41],5,4);
	if(EndOfSec(&buffer[41],5))
		return true;

	m_dK2 = StrToDouble(&buffer[46],5,4);
	if(EndOfSec(&buffer[46],5))
		return true;

	m_dK3 = StrToDouble(&buffer[51],5,4);
	if(EndOfSec(&buffer[51],5))
		return true;

	m_dK = StrToDouble(&buffer[56],5,3);
	if(EndOfSec(&buffer[56],5))
		return true;

	m_dVsmax = StrToDouble(&buffer[61],5,3);
	if(EndOfSec(&buffer[61],5))
		return true;

	m_dVsmin = StrToDouble(&buffer[66],5,3);
	if(EndOfSec(&buffer[66],5))
		return true;

	m_dKp = StrToDouble(&buffer[71],5,4);
	if(EndOfSec(&buffer[71],5))
		return true;

	m_dKmva = StrToDouble(&buffer[76],4,0);
	if(EndOfSec(&buffer[76],4))
		return true;

	return true;
}

bool CSH_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSH_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dTd,&buffer[16],5,4);
	DoubleToStr(m_dT1,&buffer[21],5,3);
	DoubleToStr(m_dT2,&buffer[26],5,3);
	DoubleToStr(m_dT3,&buffer[31],5,3);
	DoubleToStr(m_dK0,&buffer[36],5,4);
	DoubleToStr(m_dK1,&buffer[41],5,4);
	DoubleToStr(m_dK2,&buffer[46],5,4);
	DoubleToStr(m_dK3,&buffer[51],5,4);
	DoubleToStr(m_dK,&buffer[56],5,3);
	DoubleToStr(m_dVsmax,&buffer[61],5,3);
	DoubleToStr(m_dVsmin,&buffer[66],5,3);
	DoubleToStr(m_dKp,&buffer[71],5,4);
	DoubleToStr(m_dKmva,&buffer[76],4,0);

	return true;
}